﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using LtccApi.Models;
using Microsoft.AspNetCore.Mvc;

namespace LtccApi.Controllers
{
    /// <summary>
    /// 轿车店铺轮胎
    /// </summary>
    [Route("api/[Controller]")]
    [ApiController]
    public class StoreCarTireController : Controller
    {
        private LtccContext mLtccContext;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="ltccContext"></param>
        public StoreCarTireController(LtccContext ltccContext)
        {
            mLtccContext = ltccContext;
        }

        /// <summary>
        /// 汽车店铺轮胎
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public IActionResult List(StoreQuery storeQuery)
        {
            var qurerResult = mLtccContext.StoreTires.AsQueryable();
            //过滤类型
            if(storeQuery.Type == VEHICLE_TYPE.CAR_TYPE)
            {
                qurerResult = qurerResult.Where(m => m.CarFlag == 1);
            }
            else
            {
                qurerResult = qurerResult.Where(m => m.TruckFlag == 1);
            }
            //过滤搜索文本
            if(storeQuery.SearchText != "")
            {
                qurerResult = qurerResult.Where(m => m.Name.Contains(storeQuery.SearchText));
            }
            //分页
            List<StoreTire> listData = qurerResult.Skip(storeQuery.IndexPage * storeQuery.PageSize).Take(storeQuery.PageSize).ToList();

            return Ok(listData);
        }
    }
}